package com.gitee.lw114514.tliasweb.controller;

import com.gitee.lw114514.tliasweb.pojo.Emp;
import com.gitee.lw114514.tliasweb.pojo.LoginInfo;
import com.gitee.lw114514.tliasweb.pojo.Result;
import com.gitee.lw114514.tliasweb.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/login")
public class LoginController {
    @Autowired
    private EmpService empService;

    @PostMapping
    public Result login(@RequestBody Emp emp) {
        log.info("用户登录，用户信息：{}", emp);
        LoginInfo loginInfo = empService.login(emp);
        if(loginInfo != null){
            log.info("用户登录成功，用户信息：{}", loginInfo);
            return Result.success(loginInfo);
        }
        log.info("用户登录失败");
        return Result.error("用户名或密码错误");
    }
}
